package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.FirstDepart;
import com.noahplat.person.pojo.SecondDepart;
import com.noahplat.person.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: FirstDepartController
 * @Description: 科室分类对外接口
 * @Author 李景星
 * @Date 2021/3/5
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/depart")
@Validated
public class DepartController {

    @Autowired
    private DepartService departService;

    /**
     * 查询所有分类信息
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:getAllDepart')")
    @GetMapping("/getAllDepart")
    public Result getAllDepart(){
        return departService.getAllDepart();
    }

    /**
     * 获得二级分类信息
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:getSDepart')")
    @GetMapping("/getSDepart")
    public Result getSDepart(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit){
        return departService.getSDepart(page, limit);
    }

    /**
     * 添加一级分类信息
     * @param firstDepart
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:addFDepart')")
    @PostMapping("/addFDepart")
    public Result addFDepart(@RequestBody FirstDepart firstDepart){
        return departService.addFDepart(firstDepart);
    }

    /**
     * 添加二级分类信息
     * @param secondDepart
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:addSDepart')")
    @PostMapping("/addSDepart")
    public Result addSDepart(@RequestBody SecondDepart secondDepart){
        return departService.addSDepart(secondDepart);
    }

    /**
     * 修改一级分类信息
     * @param firstDepart
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:updateFDepart')")
    @PutMapping("/updateFDepart")
    public Result updateFDepart(@RequestBody FirstDepart firstDepart){
        return departService.updateFDepart(firstDepart);
    }

    /**
     * 修改二级分类信息
     * @param secondDepart
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:updateSDepart')")
    @PutMapping("/updateSDepart")
    public Result updateSDepart(@RequestBody SecondDepart secondDepart){
        return departService.updateSDepart(secondDepart);
    }

    /**
     * 分页获取一级分类信息
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:getAdminFDepart')")
    @GetMapping("/getAdminFDepart")
    public Result getAdminFDepart(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit){
        return departService.getAdminFDepart(page, limit);
    }

    /**
     * 获得一级分类信息
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:getFDepart')")
    @GetMapping("/getFDepart")
    public Result getFDepart(){
        return departService.getFDepart();
    }

    /**
     * 通过ID获取一级分类详细信息
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:getFDepartById')")
    @GetMapping("/getFDepartById")
    public Result getFDepartById(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return departService.getFDepartById(id);
    }

    /**
     * 删除一级分类信息
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:delFDepart')")
    @DeleteMapping("/delFDepart")
    public Result delFDepart(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return departService.delFDepart(id);
    }

    /**
     * 获得根据id二级分类信息
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:getSDepartById')")
    @GetMapping("/getSDepartById")
    public Result getSDepartById(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return departService.getSDepartById(id);
    }

    /**
     * 删除二级分类信息
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DepartController:delSDepart')")
    @DeleteMapping("/delSDepart")
    public Result delSDepart(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return departService.delSDepart(id);
    }

}
